import React, { Component } from 'react'

export default class Footer extends Component {

  // 全选checkbox的回调
  handleCheckAll = (e)=>{
    this.props.allTodo(e.target.checked)
  }

  render() {
    const { todos } = this.props
    // 已完成的个数
    const doneCount = todos.reduce((pre, current) => pre + (current.done ? 1 : 0), 0)
   
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" onChange={this.handleCheckAll} checked={doneCount === todos.length && ( todos.length !== 0)?true:false} />
        </label>
        <span>
          <span>已完成{doneCount}</span> / 全部{todos.length}
        </span>
        <button className="btn btn-danger">清除已完成任务</button>
      </div>
    )
  }
}
